<?php
namespace App\Scopes\Admin;

use App\Request\FormRequest;
use Hyperf\Context\Context;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\Scope;
use function Hyperf\Support\make;

Class AdminLog implements Scope {

    public function apply(Builder $builder, Model $model)
    {
        $request = make(FormRequest::class);
        $app = $request->appName();
        $infoName = "{$app}Info";
        $info = Context::get($infoName);
        if ($info['is_admin'] == 0) {
            // TODO: Implement apply() method.
            $builder->where('admin_id', $info['id']);
        }
        $builder->where('app', $app);
    }

}